-
Notifications
You must be signed in to change notification settings - Fork 2
/
clock.c
55 lines (40 loc) · 1.59 KB
/
clock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*++
toro C Library
https://github.com/KilianKegel/toro-C-Library#toro-c-library-formerly-known-as-torito-c-library
Copyright (c) 2017-2024, Kilian Kegel. All rights reserved.
SPDX-License-Identifier: GNU General Public License v3.0
Module Name:
clock.c
Abstract:
Implementation of the Standard C function.
Calculates the wall-clock time used by the calling process.
Author:
Kilian Kegel
--*/
#include <CdeServices.h>
#include <time.h>
#include <stdio.h>
/**
Synopsis
#include <time.h>
clock_t clock(void);
Description
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/clock?view=msvc-160
The clock function determines the processor time used.
Returns
The clock function returns the implementation’s best approximation to the processor
time used by the program since the beginning of an implementation-defined era related
only to the program invocation. To determine the time in seconds, the value returned by
the clock function should be divided by the value of the macro CLOCKS_PER_SEC.
If the processor time used is not available or its value cannot be represented, the function
returns the value (clock_t)(-1)
@param[in] void
@retval time_t, calendar time
**/
clock_t clock(void)
{
CDE_APP_IF* pCdeAppIf = __cdeGetAppIf();
unsigned long long cps = pCdeAppIf->pCdeServices->TSClocksPerSec / CLOCKS_PER_SEC;
unsigned long long clk = (pCdeAppIf->pCdeServices->pGetTsc(pCdeAppIf) - pCdeAppIf->pCdeServices->TSClocksAtSystemStart);
return (clock_t)(clk / cps);
}